//
//  BQTypeCVCell.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/4/26.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQTypeCVCell.h"
#import "BQTypeLayout.h"
#import <Masonry.h>
#import "BQTypeCell.h"
#import "UIColor+HMAddition.h"

#import "BQHomeModel.h"
#import "BQAccountManager.h"
#import <YYModel/YYModel.h>

@interface BQTypeCVCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UICollectionView *collectionView;

@end
static NSString *Type_Cell = @"Type_Cell";
@implementation BQTypeCVCell{
    
    NSArray *_dataArray;
    
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self loadData];
        
        [self setupUI];
        
        
    }
    
    return self;
}

-(void)setupUI{
    
    UICollectionView *typeCV = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:[BQTypeLayout new]];
    
    typeCV.backgroundColor = [UIColor whiteColor];
    
    _collectionView = typeCV;
    
    typeCV.delegate = self;
    
    typeCV.dataSource = self;
    
    
    [typeCV registerClass:[BQTypeCell class] forCellWithReuseIdentifier:Type_Cell];
    
    [self.contentView addSubview:typeCV];
    
    [typeCV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 4;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BQTypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Type_Cell forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    BQHomeModel *model = _dataArray[indexPath.item];
    
    cell.model = model;

    return cell;
    
}

-(void)loadData{
    
    NSDictionary *para = @{@"call" : @1};
    
    [_AccountMgr POSTWithUrlString:focus_url parameters:para success:^(id responseObject) {
        
        // 获取分类模型数组
        NSArray *dictArray = responseObject[@"data"][@"icons"];
        
        _dataArray = [NSArray yy_modelArrayWithClass:[BQHomeModel class] json:dictArray];
        
        [self.collectionView reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

    
    
}



@end
